/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simplemetrosystem.view.table;

import java.awt.GridBagLayout;
import javax.swing.JButton;
import javax.swing.JPanel;
import simplemetrosystem.model.charlanguage.NameMap;
import simplemetrosystem.view.Layout.GBC;
import simplemetrosystem.view.InformationPane;
import simplemetrosystem.view.action.NewEdgeActionListener;
import simplemetrosystem.view.action.RemoveEdgeActionListener;

/**
 *
 * @author Eric Qian
 */
public class AllEdgeTableToolPane extends JPanel {

    /**
     * 
     * @param infPane
     */
    public AllEdgeTableToolPane(InformationPane infPane) {
        this.infPane = infPane;
        nameMap = NameMap.getInstance();
        loadComponent();
    }

    private void loadComponent() {
        setLayout(new GridBagLayout());

        add(getAddEdgeButton(), new GBC(0, 0).setWeight(0, 0).setInsets(0, 2, 0, 2));
        add(getRemoveEdgeButton(), new GBC(1, 0).setWeight(0, 0).setInsets(0, 2, 0, 2));
        add(getSearchPane(), new GBC(2, 0).setWeight(100, 0).setFill(GBC.BOTH));
    }

    private JButton getAddEdgeButton() {
        if (addEdgeButton == null) {
            addEdgeButton = new JButton();
            addEdgeButton.setText(nameMap.getName("New Edge"));
            addEdgeButton.setToolTipText(nameMap.getName("New Edge"));
            addEdgeButton.addActionListener(new NewEdgeActionListener(infPane.getFrame()));
        }
        return addEdgeButton;
    }

    private JButton getRemoveEdgeButton() {
        if (removeEdgeButton == null) {
            removeEdgeButton = new JButton();
            removeEdgeButton.setText(nameMap.getName("Remove Edge"));
            removeEdgeButton.setToolTipText("Remove Edge");
            removeEdgeListener = new RemoveEdgeActionListener(infPane.getFrame(),null);
            removeEdgeButton.addActionListener(removeEdgeListener);
        }
        return removeEdgeButton;
    }

    private SearchPane getSearchPane() {
        if (searchPane == null) {
            searchPane = new SearchPane(infPane);
        }
        return searchPane;
    }
    private InformationPane infPane;
    private NameMap nameMap;
    private RemoveEdgeActionListener removeEdgeListener;
    private JButton addEdgeButton;
    private JButton removeEdgeButton;
    private SearchPane searchPane;
}
